import {withRouter} from "next/router"
import React from "react"
import axios from 'axios'

const Detail = ({router, id, list}) => {
  return (
    <>
      <h1>带参页面</h1>
      <p>参数：{id || '无'}</p>
      <p>data: {JSON.stringify(list)}</p>
    </>
  )
}

Detail.getInitialProps = async (router) => {
  const {id} = router.query
  const res = await axios.get('https://api.coinmarketcap.com/v1/ticker/?limit=3&convert=CNY')

  console.log(res.data)

  return {
    id,
    list: res.data || []
  }
}

export default withRouter(Detail)
